package com.bingfor.easycablelink.home.Fragment.Cable;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bingfor.easycablelink.base.BaseFragment;
import com.bingfor.easycablelink.databinding.CableFragmentBinding;
import com.bingfor.easycablelink.utils.ToastUtil;
import com.bingfor.easycablelink.widgets.RefreshableView;

import java.util.ArrayList;
import java.util.List;


/**
*主页 -  线缆
*@author LY
*@time 2017/5/19 16:53
* des:create file and achieve model
*/
public class CableFragment extends BaseFragment implements RefreshableView.PullToRefreshListener {

    CableFragmentBinding binding ;
    List<String> titles = new ArrayList<>();
    CableAdapter adapter = new CableAdapter(titles);
    public RecyclerView.LayoutManager mLayoutManager = null;
    int page;

    public CableFragment(int page) {
        this.page = page;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = CableFragmentBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated( Bundle savedInstanceState ){
        super.onActivityCreated(savedInstanceState);
        initViews();
    }

    @Override
    public void refresh() {

    }

    @Override
    public void initViews() {
        titles.add("1");
        titles.add("2");
        titles.add("3");
        titles.add("4");

        List<String> urls = new ArrayList<>();

        urls.add("http://img2.imgtn.bdimg.com/it/u=2670750920,766573320&fm=214&gp=0.jpg");
        urls.add("http://pic.58pic.com/58pic/13/61/00/61a58PICtPr_1024.jpg");
        urls.add("http://img1.imgtn.bdimg.com/it/u=451884888,666487513&fm=23&gp=0.jpg");
        binding.mRefreshableView.setOnRefreshListener(new RefreshableView.PullToRefreshListener() {
            @Override
            public void onRefresh() {
                Log.e("d","ddd");
//                binding.mRefreshableView.finishRefreshing();
            }
        },page);
        binding.mRecyclerView.setLayoutManager(mLayoutManager = new LinearLayoutManager(mContext));
//        binding.mRecyclerView.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL));
        binding.mRecyclerView.setAdapter(adapter);
        adapter.setUrls(urls);

    }

    @Override
    public void initToolbar() {

    }

    public static CableFragment getInstance(int Page) {


        return new CableFragment(Page);
    }

    @Override
    public void onRefresh() {
        ToastUtil.showToast("start");

    }
}

